home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Video Toaster 4.0
/
Video Toaster v4.0.iso
/
arexx
/
cg
/
spellcheck.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1995-02-16
|
7KB
|
236 lines
/***********************************************************************/
/* SpellChecker.rexx V1.5 -- A REAL simplistic Spealchecker. */
/* By Bob Caron ©Feb,10 1995 NewTek, Inc. */
/* */
/* This needs Addword,WordHost and Words in the */
/* rexx:cg/SpellCheck_support directory. Rexx: Should be assigned to */
/* it's normal directory AND toaster:arexx */
/* example: assign rexx: toaster:arexx add */
/***********************************************************************/
call remlib(CG_AREXX)
call remlib(SPELLER_PORT)
call addlib(CG_AREXX,0)
call addlib(SPELLER_PORT,0)
call pragma(d,"rexx:CG/SpellCheck_Support")
if exists(words)=0 then do
call req_tell("Error! wordfile is missing.")
if exists(words.bu) then
if req_ask("Use backup word file?") then
address command "copy words.bu words"
if exists(words)=0 then do
call req_tell("Backup file is also missing!","Replace 'rexx:cg/spellcheck_support/words'")
__QUIT
call req_bar("ToasterCG")
call remlib(CG_AREXX)
call remlib(SPELLER_PORT)
exit
end
end
if exists(WordHost)=0 then do
req_tell("ERROR! WordHost Program Missing!","It needs to be in 'Rexx/cg/Spellcheck_support'")
call req_bar("ToasterCG")
exit
end
address command "run rexx:cg/SpellCheck_Support/wordhost rexx:cg/SpellCheck_Support/words"
options results
address "SPELLER_PORT"
IF ~SHOW('Ports',SPELLER_PORT) THEN do
call REQ_TELL("WordHost Not Found!!","It should be in REXX:CG/SpellCheck_Support","with the wordfile.")
call req_bar("ToasterCG")
call remlib(CG_AREXX)
call remlib(SPELLER_PORT)
exit
end
misword=0
totword=0
addwords=0
current_line=1
total_lines=GET_PAGE(SIZE)
call req_bar("Checking: %0")
if req_ask("SpellChecker V1.5","","Hit OK To check page.")=0 then do
__QUIT
call req_bar("ToasterCG")
call remlib(CG_AREXX)
call remlib(SPELLER_PORT)
exit
end
do while current_line <= total_lines
call SET_LINE(current_line)
line_pos=GET_LINE(SPOT)
line=GET_LINE()
call req_bar("Checking: %"||trunc(current_line/(total_lines)*100))
call checkline(line)
current_line=current_line+1
end
if addword=1 then do
call req_bar("Adding Words...")
call addword()
end
__QUIT
call REQ_TELL("All Done!",misword||" mispelled words.",totword||" words total.")
call req_bar("ToasterCG")
call remlib(CG_AREXX)
call remlib(SPELLER_PORT)
exit
/* Subroutines */
checkline: /* Cut up a line and check it */
parse arg line
word_count=1
uncleanline=line
wordlocation=0
line=cleanline(line)
current_word=word(line,word_count)
do while(current_word~="")
word_temp=current_word
current_word=striper(current_word)
current_word
totword=totword+1
if result=0 then do
fixedword=""
inword=REQ_STRING("Unknown word... Correct word or Continue.",word_temp)
if inword="" then fixedword=word_temp
else
fixedword=inword
call req_bar("Checking: %"||trunc(current_line/(total_lines)*100))
skipquestion=0
if fixedword~=word_temp then do
uncleanline=change_word(uncleanline,word_temp,fixedword,wordlocation)
word_temp=fixedword
skipquestion=1
end
misword=misword+1
if skipquestion=0 then do
ask=req_ask("Add '"||word_temp||"' To Dictionary?")
if ask=1 then do
addword=1
output='c:echo "'||word_temp||'" >> rexx:cg/spellcheck_support/word_temp'
address command output
end
call req_bar("Checking: %"||trunc(current_line/(total_lines)*100))
end
end
wordlocation=wordlocation+length(current_word)
word_count=word_count+1
current_word=word(line,word_count)
end
return
/* Strip non-alpha char's and arg it to uppercase for ease of checking */
striper:
arg current_word
newword=''
count=1
do while (count<=length(current_word))
current_char=substr(current_word,count,1)
if (C2D(current_char)>64) & (C2D(current_char)<91) | (C2D(current_char)=39) then newword=newword||current_char
count=count+1
end
return newword
/* change a word on a line <Ok so it buggers up if it has the same */
/* word on the same line... I'll fix that one day! HONEST! */
change_word:
parse arg line,word,word2,wordlocation
word2=space(word2)
wordlocation=wordlocation-length(word2)
if wordlocation-1 <1 then wordlocation=1
location=pos(word,line,(wordlocation))-1
word_length=length(word)
end_location=word_length+location
count=1
if location <=0 then location=0
do while (count<=word_length)
if substr(word2,count,1)=' ' then do
call killchar()
location=location
end
else do
call SET_CHAR(SPOT,count+location)
call SET_CHAR(substr(word2,count,1))
call pickchar()
font=get_font()
chsize=get_font(size)
call set_char(spot,count+location+1) /*Ok so the cursor will wobble!*/
end
count=count+1
end
location=(location+(count))
call SET_CHAR(FACE,font,chsize)
call SET_CHAR(SPOT,location)
length1=length(word)
length2=length(word2)
diff=length2-length1
wordlocation=wordlocation-diff
extra=0
if length1<length2 then do
do while (extra<diff)
if substr(word2,(length1+1)+extra,1)~=' ' then
call pickchar()
call makechar(substr(word2,(length1+1)+extra),1)
extra=extra+1
end
end
return get_line()
cleanline: /* Remove a wudge of non-alpha char's */
parse arg line
line=translate(line," ","/*=:.;:<>+-!@#$%^&*()_|\[]{}?~`0123456789,")
line=translate(line," ",d2c(34))
line=translate(line," ",d2c(40))
line=translate(line," ",d2c(41))
return line
/* This bit is a BIT path dependent... I'll tie it into default paths */
/* some year... */
addword:
call pragma(d,"rexx:CG/SpellCheck_Support")
if exists('rexx:cg/spellcheck_support/addword')=0 then do
req_tell("AddWord Program Missing!","It needs to be in 'Rexx/cg/Spellcheck_support'")
call req_bar("ToasterCG")
return
end
address command "c:sort word_temp word_temp.srt"
address command "delete words.bu2"
address command "rename Toaster:Arexx/cg/spellcheck_support/words.bu Toaster:Arexx/cg/spellcheck_support/words.bu2"
address command "rename Toaster:Arexx/cg/spellcheck_support/words Toaster:Arexx/cg/spellcheck_support/words.bu"
if exists(word_temp.srt) then
address command "addword Toaster:Arexx/cg/spellcheck_support/words.bu Toaster:Arexx/cg/spellcheck_support/word_temp.srt Toaster:Arexx/cg/spellcheck_support/new_words"
else
call req_tell("Error! adding words!","Couldn't create temp file.")
if exists("Toaster:Arexx/cg/spellcheck_support/new_words") then do
address command "rename Toaster:Arexx/cg/spellcheck_support/new_words Toaster:Arexx/cg/spellcheck_support/words"
address command "delete Toaster:Arexx/cg/spellcheck_support/word_temp"
address command "delete Toaster:Arexx/cg/spellcheck_support/word_temp.srt"
end
else
call req_tell("Error! Creating new Wordfile")
return
/* $VER:Spellcheck V1.5 2-14-95 <I Just GOTTTA have a wildebeest!>
*/